import { emitter } from "./event";

export const useEventHandle = () => {
  const handleClickQuery = (componentId, currentId, obj) => {
    emitter.emit(`query${componentId}by${currentId}`, { ...obj, componentId });
    // console.log("eventNames", emitter.eventNames());
  };

  const queryHandler = (componentId, currentId, func) => {
    emitter.removeAllListeners(`query${componentId}by${currentId}`);
    emitter.on(`query${componentId}by${currentId}`, function (value) {
      func(value);
    });
  };

  return {
    handleClickQuery,
    queryHandler,
  };
};
